<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link href="css/mui.min.css" rel="stylesheet" />
		<link href="css/mui.indexedlist.css" rel="stylesheet" />
		<link href="style/fjol_style.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="style/xol_style.css"/>
		<style>
			html,
			body {
				height: 100%;
				overflow: hidden;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav newbgRed">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">城市列表</h1>
		</header>
		<div class="mui-content">
			<div class="mui-group-list-bar rel">
				<!-- 侧边字母 -->
				<div id="cityLetter">

				</div>
			</div>
			<div class="mui-scroll-wrapper" style="top: 45px;" id="refreshContainer">
				<div class="mui-scroll">
					<!--这里放置真实显示的DOM内容-->
					<p>当前城市</p>
					<ul class="mui-table-view mb10">
						<li class="mui-table-view-cell" id="curCity">

						</li>
					</ul>

					<ul class="mui-table-view cities-list" id="citiesList">

					</ul>
				</div>
			</div>

		</div>
	</body>
	<script src="js/mui.min.js"></script>
	<script src="js/jquery-2.1.0.js"></script>
	<script src="js/jQuery.Hz2Py-min.js"></script>
	<script src="js/fj_public_js.js"></script>
	<script src="js/md5.js"></script>
	<script src="js/enum.util.js"></script>
	<script src="js/generalUtil.js"></script>
	<script src="js/fj_base_data.js"></script>
	<script src="js/network.js"></script>
	<script src="js/fj_area_util.js"></script>
	<script type="text/javascript" charset="utf-8">
		mui.init();

		function plusReady() {

			plus.nativeUI.closeWaiting(); //这里监听页面是否加载完毕，完成后关闭等待框

			var net = fjNetwork;
			getBaseData(net);
			var areaUtil = areaUtils;
			areaUtil.setNetworkClient(net);
			//获取城市列表
			var areaLevelCity = 2;

			areaUtil.getAreaListByLevel(areaLevelCity, function() {

				var currentCity = areaUtil.getCurrentCity();

				if(currentCity == null) {
					areaUtil.setCurrentCityByCityName('泉州市');
				}

			});

			var currentCityName = areaUtil.getCurrentCity();
			document.querySelector('#curCity').innerHTML = currentCityName.areaName;

			var childAreaList = areaUtil.getCurrentCityChileAreaList();

			var citiesList = areaUtil.getCityList();

			var data = new Array();
			var childList = new Array();
			var finalchildList = new Array();

			for(var i = 0; i < citiesList.length; i++) {
				//	console.log(citiesList[i]);
				childList.push(citiesList[i]);
			}
			for(var i = 0; i < childAreaList.length; i++) {
				var childArea = childAreaList[i];
				var finalAreaList = childArea.arrayChildArea;
				//					console.log(childArea[i].areaName);
				for(var j = 0; j < finalAreaList.length; j++) {
					var finalArea = finalAreaList[j];
					//						console.log('------'+finalArea.areaName);
					finalchildList.push(finalArea.areaName);
				}

			}

			var showCityList = document.getElementById('citiesList');

			//fj_public.js按字母排序后得到城市数组
			var pushCities = sortCity(childList);

			for(item in pushCities) {
				if(typeof(pushCities[item]) == 'string') {
					data.push('<li class="mui-table-view-cell citiesLi">' + pushCities[item] + '</li>');

				} else {
					data.push('<li class="mui-table-view-cell citiesLi" id="' + pushCities[item].identId + '">' + pushCities[item].areaName + '</li>');
				}

			}
			showCityList.innerHTML = data.join(''); // 使用join生成最终字符串   

			var wv = plus.webview.currentWebview();
			var parentId = wv.parentId;
			//	console.log(parentId);

			(function($) {
				function getElement(obj) {
					_obj = '#' + obj;
					return $(_obj);
				}

				var domTop = [];
				for(var i = 0; i < $('.citiesLi p').length; i++) {

					$('#cityLetter').append('<a>' + $('.citiesLi p').eq(i).attr('id') + '</a>');
					domTop[i] = $('.citiesLi p').eq(i).offset().top;

				}

				$('#cityLetter a').each(function() {
					$(this).click(function() {
						var letterId = $(this).text();
						var letterIdx = $(this).index();

						mui('#refreshContainer').scroll().scrollTo(0, -domTop[letterIdx] + 60);

					});
				});

				$('.citiesLi').each(function() {
					$(this).click(function() {

						if($(this).children().length == 1) {

							return false;
						} else {
							if(parentId == 'xol_index') {
//								indexPage = plus.webview.getWebviewById('xol_index');
								indexPage = plus.webview.currentWebview().opener();
								mui.fire(indexPage, 'getCityList', { //自定义函数 返回首页城市
									cityName: $(this).text(),
									cityIdentId: $(this).attr('id')
								});
								areaUtil.setCurrentCityByCityName($(this).text()); //设置当前城市

							}
							if(parentId == 'fj_subscribe') {
								indexPage = plus.webview.getWebviewById('fj_subscribe');
								mui.fire(indexPage, 'getCityName', { //自定义函数 返回订阅
									cityName: $(this).text(),
									cityIdentId: $(this).attr('id')
								});

							}

							mui.back();
						}
					})
				})
			})(jQuery);

		}
		document.addEventListener("plusready", plusReady, false);
	</script>

</html>